﻿using Microsoft.SqlServer.Server;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;

namespace scanner.utils
{
    internal class IniHelper
    {
        private static string filePath;

        public static void setFilePath(string iniFilePath) {
            filePath = iniFilePath;
        }

        [DllImport("kernel32")]
        private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);

        [DllImport("kernel32")]
        private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);

        public static void write(string section, string key, string value)
        {
            WritePrivateProfileString(section, key, value, filePath);
        }

        public static string readFile(string key, string sectoin="packages") {
            if (!File.Exists(filePath)) {
                File.Create(filePath).Close();
                return null;
            }

            StringBuilder sb = new StringBuilder(255);
            GetPrivateProfileString(sectoin, key, "1", sb, 255, filePath);
            return sb.ToString();
        }        
    }
}
